package com.example.ItPhotoAlbumCloud.utils;


/**
 * 字符串工具类
 * 小仙 创建人 2023-03-12 08:54:11
 */
public class StringUtils {

    /**
     * 不为空判断，不等于 null or "" 时返回true
     * @param str
     * @return
     */
    public static boolean isNotEmpty(String str) {
        if (str == null || str.isEmpty()) {
            return false;
        }
        return true;
    }

    /**
     * 不为空格判断，不等于 null or "" or " " 时返回true
     * @param str
     * @return
     */
    public static boolean isNotBlank(String str) {
        if (str == null || str.isEmpty()) {
            return false;
        }

        str = str.trim();
        return str.length() != 0;
    }

    /**
     * 空格判断，仅有空格时返回true
     * @param str
     * @return
     */
    public static boolean isBlank(String str) {
        if (str == null || str.isEmpty()) {
            return false;
        }

        str = str.trim();
        return str.length() == 0;
    }

    /**
     * 判断两个字符串是否一致
     * @return
     */
    public static boolean equals(String a, String b) {
        if (a == null || b == null) {
            return false;
        }

        return a.equals(b);
    }

    /**
     * params是否包含value
     * @param value
     * @param params
     * @return
     */
    public static boolean contains(String value, String... params){
        if (null == value || null == params || params.length == 0){
            return false;
        }

        for (String item : params){
            if (equals(item, value)){
                return true;
            }
        }

        return false;
    }


    /**
     * 字符连接
     * @param param 等于null会返回空字符串
     * @return
     */
    public static String compose(String... param){

        if (param == null || param.length == 0) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        for (String item : param) {
            if (isNotEmpty(item)) {
                sb.append(item);
            }
        }

        return sb.toString();
    }
}

